import Vue from 'vue'
import Vuex from 'vuex'
Vue.use(Vuex)
const store = new Vuex.Store({
	state: {
		hasLogin: false,//是否登录
		forceLogin:false,//是否需要强制登录
		username:'',//用户名(昵称)
		userId:'',//用户ID
		password:'',
		token:'',
		userInfo:{},
		tabbar: [{
						iconPath: "home",
						selectedIconPath: "home-fill",
						text: '首页',
						isDot: false,
						customIcon: false,
						pagePath: "/pages/article/article",
					},
					{
						iconPath: "chat",
						selectedIconPath: "chat-fill",
						text: '问答',
						customIcon: false,
						pagePath: "/pages/chat/chat",
					},
					{
						iconPath: "grid",
						selectedIconPath: "grid-fill",
						text: '体系',
						customIcon: false,
						pagePath: "/pages/system/system",
					},
					{ 
						iconPath: "account",
						selectedIconPath: "account-fill",
						text: '我的',
						isDot: false,
						customIcon: false,
						pagePath: "/pages/mypage/mypage",
					},
				]
	},
	mutations: {
		login(state, provider) {
			state.hasLogin = true;
			state.userInfo = provider;
			state.username = provider.nickname;
			state.password = provider.password
			state.userId = provider.id;
			state.token = provider.token
			uni.setStorage({ //缓存用户登陆状态
				key: 'userInfo',
				data: provider
			})
			
			//Cookie格式`loginUserName=qoow;loginUserPassword=123456`;
			uni.setStorage({ //缓存用户登陆状态
				key: 'cookie',
				data: 'loginUserName='+provider.username+';loginUserPassword='+provider.password
			})
		},
		logout(state) {
			state.hasLogin = false;
			state.userInfo = '';
			state.username = '';
			state.password = '';
			state.userId = '';
			state.userInfo = {};
			uni.removeStorage({
				key: 'userInfo',
				key: 'cookie'
			})
		}
	},
	actions: {

	}
})

export default store


